package com.zzl.finance.data.controller;

import java.util.Arrays;
import java.util.Map;

import com.zzl.apidoc.annotation.ApidocController;
import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.general.common.apidoc.annotation.ApidocParamsPage;
import com.zzl.general.common.apidoc.annotation.ApidocResultKeyValR;
import com.zzl.general.common.apidoc.annotation.ApidocReturnPage;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.apidoc.constants.ResultTypeInR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.utils.LogUtils;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Result;
import com.zzl.general.common.exception.SysException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;

import com.zzl.finance.data.entity.FinancialProductRateEntity;
import com.zzl.finance.data.dto.FinancialProductRateAddDto;
import com.zzl.finance.data.dto.FinancialProductRateUpdateDto;
import com.zzl.finance.data.service.FinancialProductRateService;
/**
 * 机构参数表，即金融产品利率表
 *
 * @author gull
 * @date 2022-07-01 18:23:11
 */
@ApidocController("机构参数表，即金融产品利率表")
@RestController
@SuppressWarnings("javadoc")
        @RequestMapping("data/financialproductrate")
    @Slf4j
public class FinancialProductRateController extends WebBaseCtrl {
    @SuppressWarnings("all")
    @Autowired
    private FinancialProductRateService financialProductRateService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApidocOperation(description = "分页查询机构参数表，即金融产品利率表数据", operationId = "data/financialproductrate" + "/list")
    @ApidocReturnPage(genericTypeClass = FinancialProductRateEntity.class)
    public Result list(@ApidocParamsPage(name = "params") @RequestParam Map<String, Object> params) {
        PageUtils page = financialProductRateService.queryPage(params);
        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApidocOperation(description = "通过id获取机构参数表，即金融产品利率表数据", operationId = "data/financialproductrate" + "/info/{id}")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "financialProductRate", valueClass = FinancialProductRateEntity.class)
    })
    public Result info(@ApidocParam(description = "机构参数表，即金融产品利率表id", name = "id", required = true) @PathVariable("id") String id) {
            FinancialProductRateEntity financialProductRate = financialProductRateService.getById(id);
        return Result.ok().put("data", financialProductRate);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApidocOperation(description = "保存机构参数表，即金融产品利率表", operationId = "data/financialproductrate" + "/save")
    @ApidocReturnR
    public Result save(@ApidocParam(description = "保存的机构参数表，即金融产品利率表对象值", name = "{financialProductRate}", required = true) @RequestBody FinancialProductRateAddDto financialProductRate) {
        try {
                financialProductRateService.saveFinancialProductRate(financialProductRate, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApidocOperation(description = "修改机构参数表，即金融产品利率表", operationId = "data/financialproductrate" + "/update")
    @ApidocReturnR
    public Result update(@ApidocParam(description = "修改的机构参数表，即金融产品利率表对象值", name = "financialProductRate", required = true) @RequestBody FinancialProductRateUpdateDto financialProductRate) {
        try {
                financialProductRateService.updateFinancialProductRateById(financialProductRate, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApidocOperation(description = "删除机构参数表，即金融产品利率表", operationId = "data/financialproductrate" + "/delete")
    @ApidocReturnR
    public Result delete(@ApidocParam(description = "删除的机构参数表，即金融产品利率表对象id集合", name = "ids", required = true) @RequestBody String[] ids) {
            financialProductRateService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
